#!/bin/bash
echo "🚀 Building Modern AI Agent System (Correct Libraries)..."
echo

WXWIN="/d/vc/wxWidgets-3.2.7"

# 检查必要的源文件
echo "📋 Checking source files..."
for file in "src/ai_agent.h" "src/agents.h" "src/ai_agent.cpp" "src/agents.cpp" "src/modern_chat_app.h" "src/modern_chat_app.cpp"; do
    if [[ ! -f "$file" ]]; then
        echo "❌ Missing: $file"
        exit 1
    fi
done
echo "✅ All source files present"

# 检查库文件是否存在
echo "📚 Checking library files..."
LIB_PATH="$WXWIN/lib"
if [[ ! -d "$LIB_PATH" ]]; then
    echo "❌ Library path not found: $LIB_PATH"
    exit 1
fi

# 列出可用的库文件
echo "🔍 Available wxWidgets libraries:"
ls "$LIB_PATH"/*.a 2>/dev/null | head -10

# Build agent system
echo "🔨 Building AI Agent System..."
g++ -std=c++17 -O2 -Wall -Wextra \
    -I"$WXWIN/include" \
    -I"$WXWIN/lib/wx/include/msw-unicode-3.2" \
    -D__WXMSW__ -D_UNICODE -DUNICODE \
    src/ai_agent.cpp \
    src/agents.cpp \
    src/modern_chat_app.cpp \
    -L"$WXWIN/lib" \
    -lwx_mswu_core-3.2 -lwx_baseu-3.2 \
    -lwx_mswu_adv-3.2 \
    -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 \
    -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid \
    -lcomctl32 -lrpcrt4 -loleacc -luxtheme \
    -o modern_ai_chat.exe

if [[ $? -eq 0 ]]; then
    echo "✅ Modern AI system built: modern_ai_chat.exe"
    echo ""
    echo "🎉 构建成功！"
    echo "📁 输出文件: modern_ai_chat.exe"
    echo ""
    echo "🚀 运行命令: ./modern_ai_chat.exe"
else
    echo "❌ Build failed, trying alternative library names..."
    
    # 尝试其他可能的库名称
    echo "🔄 Trying alternative library names..."
    g++ -std=c++17 -O2 -Wall -Wextra \
        -I"$WXWIN/include" \
        -I"$WXWIN/lib/wx/include/msw-unicode-3.2" \
        -D__WXMSW__ -D_UNICODE -DUNICODE \
        src/ai_agent.cpp \
        src/agents.cpp \
        src/modern_chat_app.cpp \
        -L"$WXWIN/lib" \
        -lwxmsw32u_core_gcc_custom -lwxbase32u_gcc_custom \
        -lwxmsw32u_adv_gcc_custom \
        -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 \
        -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid \
        -lcomctl32 -lrpcrt4 -loleacc -luxtheme \
        -o modern_ai_chat.exe
        
    if [[ $? -eq 0 ]]; then
        echo "✅ Modern AI system built with custom libraries: modern_ai_chat.exe"
        echo ""
        echo "🎉 构建成功！"
        echo "📁 输出文件: modern_ai_chat.exe"
        echo ""
        echo "🚀 运行命令: ./modern_ai_chat.exe"
    else
        echo "❌ All build attempts failed"
        exit 1
    fi
fi
